package com.blog.blogpro.common.dto;

import com.blog.blogpro.common.constant.ResultCode;


/**
 * Class Name: ResultDtoFactory
 * Description:
 *
 * @author SC
 */
public final class ResultDtoFactory {

    private ResultDtoFactory() {
    }

    public static <T> ResultDto<T> toAck(boolean linkDetail, String msg) {
        ResultDto<T> resultDto = toAck(msg, null, null);
        resultDto.setLinkDetail(linkDetail);
        return resultDto;
    }

    public static <T> ResultDto<T> toAck(String msg) {
        return toAck(msg, null, null);
    }

    public static <T> ResultDto<T> toAck(String msg, T data) {
        return toAck(msg, data, null);
    }

    public static <T> ResultDto<T> toAck(String msg, T data, Object[] args) {
        ResultDto<T> dto = new ResultDto<>();
        dto.setCode(ResultCode.ACK);
        dto.setMessage(msg);
        dto.setData(data);
        dto.setArgs(args);
        return dto;
    }


    /**
     * Description: 在controller层直接返回错误消息，避免在controller中用该方法catch异常做处理
     *
     * @param msg
     * @return
     */
    public static <T> ResultDto<T> toNack(String msg) {
        return toNack(msg, null, null);
    }

    public static <T> ResultDto<T> toNack(String msg, boolean linkDetail) {
        return toNack(msg, null, linkDetail, null);
    }



    public static <T> ResultDto<T> toNack(String msg, Object[] args) {
        return toNack(msg, null, args);
    }


    /**
     * Description: 在controller层直接返回错误消息，避免在controller中用该方法catch异常做处理
     *
     * @param msg
     * @param data
     * @return
     */
    public static <T> ResultDto<T> toNack(String msg, T data) {
        return toNack(msg, data, null);
    }

    public static <T> ResultDto<T> toNack(String msg, T data, boolean linkDetail) {
        return toNack(msg, data, linkDetail, null);
    }

    public static <T> ResultDto<T> toNack(String msg, T data, boolean linkDetail, Object[] args) {
        ResultDto<T> dto = new ResultDto<>();
        dto.setCode(ResultCode.NACK);
        dto.setMessage(msg);
        dto.setData(data);
        dto.setArgs(args);
        dto.setLinkDetail(linkDetail);
        return dto;
    }

    public static <T> ResultDto<T> toNack(String msg, T data, Object[] args) {
        ResultDto<T> dto = new ResultDto<>();
        dto.setCode(ResultCode.NACK);
        dto.setMessage(msg);
        dto.setData(data);
        dto.setArgs(args);
        return dto;
    }

}
